// 基础响应类型
export interface BaseResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface LoginRequest {
  username: string
  password: string
}

export interface LoginResponse {
  token: string
  username: string
  email: string
  realName: string
  roles: string[]
  permissions: string[]
}

// 分页响应类型
export interface PageResponse<T = any> {
  records: T[]
  total: number
  size: number
  current: number
  pages: number
}

// 用户相关类型
export interface User {
  id: number
  username: string
  realName: string
  email: string
  phone: string
  status: number
  createTime: string
  updateTime: string
}

export interface UserListParams {
  pageNum: number
  pageSize: number
  username?: string
  realName?: string
  status?: number
}

export interface UserListResponse extends PageResponse<User> {}

export interface UserCreateData {
  username: string
  realName: string
  email: string
  phone: string
  password: string
  status: number
}

export interface UserUpdateData {
  realName?: string
  email?: string
  phone?: string
  status?: number
}

// 渠道相关类型
export interface ChannelSource {
  id: number
  channelName: string
  channelCode: string
  channelType: string
  channelDirection: 'UPSTREAM' | 'DOWNSTREAM'
  apiUrl?: string
  apiKey?: string
  dailyLimit: number
  priority: number
  status: number
  description?: string
  createTime: string
  updateTime: string
}

export interface ChannelListParams {
  pageNum: number
  pageSize: number
  channelName?: string
  channelCode?: string
  channelType?: string
  channelDirection?: 'UPSTREAM' | 'DOWNSTREAM'
  status?: number
}

export interface ChannelListResponse extends PageResponse<ChannelSource> {}

export interface ChannelCreateData {
  channelName: string
  channelCode: string
  channelType: string
  channelDirection: 'UPSTREAM' | 'DOWNSTREAM'
  apiUrl?: string
  apiKey?: string
  dailyLimit: number
  priority: number
  status: number
  description?: string
}

export interface ChannelUpdateData {
  channelName?: string
  channelCode?: string
  channelType?: string
  apiUrl?: string
  apiKey?: string
  dailyLimit?: number
  priority?: number
  status?: number
  description?: string
}

// 分发方案相关类型
export interface DistributionScheme {
  id: number
  schemeName: string
  schemeCode: string
  upstreamChannels: string[]
  downstreamChannels: string[]
  rules: DistributionRule[]
  status: number
  description?: string
  createTime: string
  updateTime: string
}

export interface DistributionRule {
  id: number
  ruleName: string
  ruleType: 'GEOGRAPHIC' | 'PRODUCT_TYPE' | 'CUSTOMER_PROFILE' | 'TIME' | 'PRIORITY' | 'ROUND_ROBIN' | 'PROPORTION'
  ruleConfig: Record<string, any>
  priority: number
  status: number
  description?: string
}

export interface SchemeListParams {
  pageNum: number
  pageSize: number
  schemeName?: string
  schemeCode?: string
  status?: number
}

export interface SchemeListResponse extends PageResponse<DistributionScheme> {}

export interface SchemeCreateData {
  schemeName: string
  schemeCode: string
  upstreamChannels: string[]
  downstreamChannels: string[]
  rules: DistributionRule[]
  status: number
  description?: string
}

export interface SchemeUpdateData {
  schemeName?: string
  schemeCode?: string
  upstreamChannels?: string[]
  downstreamChannels?: string[]
  rules?: DistributionRule[]
  status?: number
  description?: string
}

// 数据处理相关类型
export interface DataProcessingConfig {
  id: number
  configName: string
  configType: 'FIELD_MAPPING' | 'SCRIPT' | 'VALIDATION'
  configContent: Record<string, any>
  status: number
  description?: string
  createTime: string
  updateTime: string
}

export interface FieldMapping {
  id: number
  sourceField: string
  targetField: string
  fieldType: string
  mappingRule: string
  transformRule?: string
  isRequired?: boolean
  description?: string
  status: number
  createTime: string
  updateTime: string
}

export interface FieldMappingCreateData {
  sourceField: string
  targetField: string
  fieldType: string
  mappingRule: string
  transformRule?: string
  isRequired?: boolean
  description?: string
  status: number
}

export interface FieldMappingUpdateData {
  sourceField?: string
  targetField?: string
  fieldType?: string
  mappingRule?: string
  transformRule?: string
  isRequired?: boolean
  description?: string
  status?: number
}

export interface ScriptConfig {
  id: number
  scriptName: string
  scriptType: string
  scriptContent: string
  status: number
  description?: string
  createTime: string
  updateTime: string
}

export interface ScriptConfigCreateData {
  scriptName: string
  scriptType: string
  scriptContent: string
  status: number
  description?: string
}

export interface ScriptConfigUpdateData {
  scriptName?: string
  scriptType?: string
  scriptContent?: string
  status?: number
  description?: string
}

export interface CollisionCheckConfig {
  id: number
  checkName: string
  checkType: 'PHONE' | 'ID_CARD' | 'EMAIL' | 'CUSTOM'
  checkRules: Record<string, any>
  checkPeriod: number
  status: number
  description?: string
  createTime: string
  updateTime: string
}

export interface CollisionCheckCreateData {
  checkName: string
  checkType: 'PHONE' | 'ID_CARD' | 'EMAIL' | 'CUSTOM'
  checkRules: Record<string, any>
  checkPeriod: number
  status: number
  description?: string
}

export interface ConfigCreateData {
  configName: string
  configType: 'FIELD_MAPPING' | 'SCRIPT' | 'VALIDATION'
  configContent: Record<string, any>
  status: number
  description?: string
}

export interface ConfigUpdateData {
  configName?: string
  configType?: 'FIELD_MAPPING' | 'SCRIPT' | 'VALIDATION'
  configContent?: Record<string, any>
  status?: number
  description?: string
}

export interface CollisionCheckUpdateData {
  checkName?: string
  checkType?: 'PHONE' | 'ID_CARD' | 'EMAIL' | 'CUSTOM'
  checkRules?: Record<string, any>
  checkPeriod?: number
  status?: number
  description?: string
}

// CRM相关类型
export interface CRMCustomer {
  id: number
  customerName: string
  phone: string
  email?: string
  idCard?: string
  company?: string
  industry?: string
  customerLevel: 'A' | 'B' | 'C' | 'D'
  status: 'NEW' | 'FOLLOWING' | 'CONVERTED' | 'INVALID'
  assignTo?: number
  createTime: string
  updateTime: string
}

export interface CRMFollowUp {
  id: number
  customerId: number
  followType: 'PHONE' | 'WECHAT' | 'EMAIL' | 'VISIT'
  followContent: string
  followResult: string
  nextFollowTime?: string
  createBy: number
  createTime: string
}

// 数据监控相关类型
export interface DataMonitor {
  id: number
  monitorName: string
  monitorType: 'REAL_TIME' | 'DAILY' | 'CUSTOM'
  monitorConfig: Record<string, any>
  alertRules: AlertRule[]
  status: number
  description?: string
  createTime: string
  updateTime: string
}

export interface AlertRule {
  id: number
  ruleName: string
  ruleType: 'THRESHOLD' | 'TREND' | 'ANOMALY'
  ruleConfig: Record<string, any>
  alertLevel: 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
  notifyChannels: string[]
  status: number
}

// 角色和权限相关类型
export interface Role {
  id: number
  roleName: string
  roleCode: string
  description?: string
  permissions?: Permission[]
  status: number
  sort: number
  createBy?: string
  createTime: string
  updateBy?: string
  updateTime: string
}

export interface RoleListParams {
  pageNum: number
  pageSize: number
  roleName?: string
  roleCode?: string
  status?: number
}

export interface RoleListResponse extends PageResponse<Role> {}

export interface RoleCreateData {
  roleName: string
  roleCode: string
  description?: string
  status: number
  sort: number
  permissions?: number[]
}

export interface RoleUpdateData {
  roleName?: string
  roleCode?: string
  description?: string
  status?: number
  sort?: number
  permissions?: number[]
}

export interface Permission {
  id: number
  permissionName: string
  permissionCode: string
  permissionType: 'MENU' | 'BUTTON' | 'API'
  parentId?: number
  path?: string
  method?: string
  status: number
  sort: number
  description?: string
  createTime?: string
  updateTime?: string
}

export interface Menu {
  id: number
  menuName: string
  menuCode: string
  menuType: 'DIRECTORY' | 'MENU' | 'BUTTON'
  parentId?: number
  path?: string
  component?: string
  icon?: string
  sort: number
  status: number
  permission?: string
  remark?: string
  children?: Menu[]
  createTime?: string
  updateTime?: string
}

export interface MenuListParams {
  menuName?: string
  menuCode?: string
  status?: number
}

export interface MenuCreateData {
  menuName: string
  menuCode: string
  menuType: 'DIRECTORY' | 'MENU' | 'BUTTON'
  parentId?: number
  path?: string
  component?: string
  icon?: string
  sort: number
  status: number
  permission?: string
  remark?: string
}

export interface MenuUpdateData {
  menuName?: string
  menuCode?: string
  menuType?: 'DIRECTORY' | 'MENU' | 'BUTTON'
  parentId?: number
  path?: string
  component?: string
  icon?: string
  sort?: number
  status?: number
  permission?: string
  remark?: string
}

// 租户相关类型
export interface Tenant {
  id: number
  tenantName: string
  tenantCode: string
  contactName: string
  contactPhone: string
  contactEmail: string
  status: number
  expireTime?: string
  maxUsers: number
  maxStorage: number
  remark?: string
  config?: TenantConfig
  createTime: string
  updateTime: string
}

export interface TenantConfig {
  maxApiCalls: number
  maxDataProcessing: number
  maxConcurrentUsers: number
  dataRetentionDays: number
  features: string[]
}

export interface TenantListParams {
  pageNum: number
  pageSize: number
  tenantName?: string
  tenantCode?: string
  status?: number
}

export interface TenantListResponse extends PageResponse<Tenant> {}

export interface TenantCreateData {
  tenantName: string
  tenantCode: string
  contactName: string
  contactPhone: string
  contactEmail: string
  status: number
  expireTime?: string
  maxUsers: number
  maxStorage: number
  remark?: string
  config?: TenantConfig
}

export interface TenantUpdateData {
  tenantName?: string
  contactName?: string
  contactPhone?: string
  contactEmail?: string
  status?: number
  expireTime?: string
  maxUsers?: number
  maxStorage?: number
  remark?: string
  config?: TenantConfig
}